/*
 *  @ProductName@
 *  Copyright (C) @CopyrightYear@
 *    National Institute of Advanced Industrial Science and Technology (AIST)
 *    Registration Number: @AISTRegistrationNumber@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.vuln.core.scap.nvd.rest;

import jp.go.aist.six.vuln.core.scap.nvd.NvdService;
import jp.go.aist.six.vuln.core.scap.nvd.NvdStore;
import jp.go.aist.six.vuln.core.scap.nvd.NvdXml;
import org.restlet.Application;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.Router;




/**
 *
 * @author  Akihito Nakamura, AIST
 * @version $Id: NvdApplication.java 209 2010-06-02 00:58:23Z nakamura5akihito $
 */
public class NvdApplication
    extends Application
{

    /**
     * Logger.
     */
//    private static Log _LOG = LogFactory.getLog( ManagerApplication.class );


    public static final String  BASE_PATH = "/nvd";

    public static final String  ENTRY_PATH   = BASE_PATH + "/entry/{vulnerabilityID}";
    public static final String  VULN_ID_ATTR = "vulnerabilityID";

    public static final String  ALL_ID_PATH   = BASE_PATH + "/id";



    private NvdService  _nvdService;
    private NvdStore  _nvdStore;
    private NvdXml    _nvdXml;



    /**
     * Constructor.
     */
    public NvdApplication()
    {
    }


    /**
     * Constructor.
     */
    public NvdApplication(
                    final Context context
                    )
    {
        super( context );
    }



    /**
     */
    protected synchronized NvdService _getNvdService()
    throws Exception
    {
        if (_nvdService == null) {
            _nvdService = new NvdService();
        }

        return _nvdService;
    }



    /**
     */
    protected synchronized NvdStore _getStore()
    throws Exception
    {
        if (_nvdStore == null) {
            _nvdStore = _nvdService.getStore();
        }

        return _nvdStore;
    }



    /**
     */
    protected synchronized NvdXml _getXml()
    throws Exception
    {
        if (_nvdXml == null) {
            _nvdXml = _nvdService.getXml();
        }

        return _nvdXml;
    }



    //**************************************************************
    //  Application
    //**************************************************************

    @Override
    public synchronized Restlet createRoot()
    {
        Router  router = new Router( getContext() );

        router.attach( ENTRY_PATH, VulnerabilityResource.class );
        router.attach( ALL_ID_PATH, AllVulnerabilityIDResource.class );

        return router;
    }

}
// NvdApplication

/* vim:set tabstop=4:set expandtab:set shiftwidth=4: */

